package com.lmk.sc.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lmk.sc.dao.UserDao;
import com.lmk.sc.entity.User;
import com.lmk.sc.service.UserService;

@Service("userService")
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao userDao;

    @Override
    public User save(User user) {
        if(user.getId() == null){
            userDao.insert(user);
        }else{
            userDao.update(user);
        }
        return user;
    }

    @Override
    public void delete(Integer id) {
        userDao.delete(id);
    }

    @Override
    public User get(Integer id) {
        return userDao.selectOne(id);
    }

    @Override
    public User findByUsername(String username) {
        return userDao.selectByUsername(username);
    }

    @Override
    public List<User> list() {
        return userDao.selectAll();
    }
}
